package com.example.questionnaire_demo;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class LifecycleDemoBean implements InitializingBean, DisposableBean {

    public LifecycleDemoBean() {
        System.out.println("## 我在LifecycleDemoBean构造函数中");
    }

    @PostConstruct
    public void postConstruct() {
        System.out.println("## PostConstruct注解的方法被调用了");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("## InitializingBean的afterPropertiesSet方法被调用了");
    }

    @PreDestroy
    public void preDestroy() {
        System.out.println("## PreDestroy注解的方法被调用了");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("## DisposableBean的destroy方法被调用了");
    }
}
